package com.enterprise.projectManager.resource;

import com.enterprise.projectManager.dto.PaySearchConditions;
import com.enterprise.projectManager.model.PayProgress;
import com.enterprise.projectManager.model.Response;
import com.enterprise.projectManager.service.implemention.PayProgressImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import static java.time.LocalDateTime.now;
import static java.util.Map.of;
import static org.springframework.http.HttpStatus.CREATED;

import static org.springframework.http.HttpStatus.OK;

@RestController
@RequiredArgsConstructor


@RequestMapping("/crebas/PayProgress")
public class PayProgressResource {
    private final PayProgressImpl payProgressService;


    @PostMapping("/createPayProgress")
    public ResponseEntity<Response> createPayProgress(@RequestBody PayProgress payProgress) {
        return ResponseEntity.ok(
                Response.builder()
                        .timeStamp(now())
                        .data(of("newPayProgress", payProgressService.createPayProgress(payProgress)))
                        .message("新建合同")
                        .status(CREATED)
                        .statusCode(CREATED.value())
                        .build()
        );
    }
    // 更新一个合同支付进度
    @PostMapping("/updatePayProgress")
    public ResponseEntity<Response> updatePayProgress(@RequestBody PayProgress payProgress) {
        return ResponseEntity.ok(
                Response.builder()
                        .timeStamp(now())
                        .data(of("updatedPayProgress",payProgressService.updatePayProgress(payProgress)))
                        .message("更新合同支付进度")
                        .status(OK)
                        .statusCode(OK.value())
                        .build()
        );
    }
    // 列出所有合同支付进度
    @GetMapping("/listAll")
    public ResponseEntity<Response> listAll() {
        return ResponseEntity.ok(
                Response.builder()
                        .timeStamp(now())
                        .data(of("payProgresses",payProgressService.listAll()))
                        .message("获取所有合同支付进度")
                        .status(OK)
                        .statusCode(OK.value())
                        .build()
        );
    }


    // 过滤
    @PostMapping("/filterProgress")
    public ResponseEntity<Response> filterCondition(@RequestBody PaySearchConditions paySearchConditions) {
        return ResponseEntity.ok(
                Response.builder()
                        .timeStamp(now())
                        .data(of("filterPayProgress",payProgressService.filterProgressBySQL(paySearchConditions)))
                        .message("查找合同支付进度")
                        .status(OK)
                        .statusCode(OK.value())
                        .build()
        );
    }
}
